package hfuu.com.cn.teasystemapp;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import hfuu.com.cn.teasystemapp.bean.operatern;
import hfuu.com.cn.teasystemapp.bean.operatesq;
import hfuu.com.cn.teasystemapp.util.listviewutil;

public class rnloglist extends AppCompatActivity {
    private List<HashMap<String, Object>> sqlogdata;
    List<operatern> operaternlist;
    SimpleAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rnloglist);
        Intent old=getIntent();

        operaternlist=new ArrayList<operatern>();
        sqlogdata=new ArrayList<HashMap<String, Object>>();
        operaternlist=(List<operatern>) old.getSerializableExtra("rnlist");
            if (operaternlist.size() > 0) {
                for (operatern rn :
                        operaternlist) {
                    HashMap<String, Object> item = new HashMap<String, Object>();
                    item.put("teaname", rn.getWarehouseteax().getWarehouseTeaname());
                    item.put("time", rn.getOperateTotaltime());
                    item.put("isfocus", false);
                    sqlogdata.add(item);
                }
                ListView sqloglist = (ListView) findViewById(R.id.sqloglist);
                ImageView back = (ImageView) findViewById(R.id.back);
                back.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                adapter = new SimpleAdapter(this, sqlogdata, R.layout.rnlogitem, new String[]{"teaname", "time"}, new int[]{R.id.teaname, R.id.time}) {
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        View view = super.getView(position, convertView, parent);
                        Boolean isFocus = (Boolean) sqlogdata.get(position).get("isfocus");

                        if (isFocus) {
                            view.setBackgroundColor(getResources().getColor(R.color.tv_gray));
                        } else {
                            view.setBackgroundColor(Color.WHITE);
                        }
                        return view;
                    }
                };
                sqloglist.setAdapter(adapter);
                listviewutil.setListViewHeightBasedOnChildren(sqloglist);
            }


    }
}
